package com.example.pertecttime.api;

import android.util.Log;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 半生瓜 on 2017/7/18.
 * http://gank.io/post/56e80c2c677659311bed9841 (参考资料)
 */

public class HttpMethosds {
    //    public static final String BASE_URL = "http://www.junxonline.com/";
    public static final String BASE_URL = "http://192.168.191.1:8080/";
    private static final int DEFAULT_TIMEOUT = 5;
    private Retrofit retrofit;
    public RetrofitService retrofitServicel;

    private HttpMethosds() {
        Log.i("api地址", "");

        OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
        httpClientBuilder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
        httpClientBuilder.networkInterceptors()
                .add(new CookiesInterceptor());
        retrofit = new Retrofit.Builder()
                .client(httpClientBuilder.build())

                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(BASE_URL)
                .build();
        retrofitServicel = retrofit.create(RetrofitService.class);

    }

    private static class SingletonHolder {
        private static final HttpMethosds INSTANCE = new HttpMethosds();
    }

    public static HttpMethosds getInstance() {
        return SingletonHolder.INSTANCE;
    }
}
